/*
 * Copyright (C) 2023, Inria
 * GRAPHDECO research group, https://team.inria.fr/graphdeco
 * All rights reserved.
 *
 * This software is free for non-commercial, research and evaluation use 
 * under the terms of the LICENSE.md file.
 *
 * For inquiries contact  george.drettakis@inria.fr
 */

#pragma once
#include <torch/extension.h>
#include <cstdio>
#include <tuple>
#include <string>


std::tuple<int, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
RasterizePointsCUDA(
	const torch::Tensor& background,	// 背景颜色
	const torch::Tensor& point3D,		// 点坐标
    const torch::Tensor& colors,		// 预计算的点的颜色
    const torch::Tensor& opacity,		// 点的不透明度
	const torch::Tensor& viewmatrix,	// 视角矩阵
	const torch::Tensor& projmatrix,	// 投影矩阵
	const float tan_fovx, 
	const float tan_fovy,
    const int image_height,
    const int image_width,
	const torch::Tensor& sh,			// 球谐系数
	const int degree,					// 球谐系数的数目
	const torch::Tensor& campos,		// 相机中心
	const bool prefiltered,				// 是否需要筛选
	const bool debug);

std::tuple<torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor, torch::Tensor>
 RasterizePointsBackwardCUDA(
	// 核心参数是 dL_dout_color
 	const torch::Tensor& background,
	const torch::Tensor& point3D,
    const torch::Tensor& colors,
	const torch::Tensor& viewmatrix,
    const torch::Tensor& projmatrix,
	const float tan_fovx, 
	const float tan_fovy,
    const torch::Tensor& dL_dout_color,
	const torch::Tensor& sh,
	const int degree,
	const torch::Tensor& campos,
	const torch::Tensor& geomBuffer,
	const int R,
	const torch::Tensor& binningBuffer,
	const torch::Tensor& imageBuffer,
	const bool debug);

// 判断哪些 Gaussian 是在当前视角下可见的，返回 bool 矩阵
torch::Tensor markVisible(
		torch::Tensor& point3D,
		torch::Tensor& viewmatrix,
		torch::Tensor& projmatrix);